package leetcode.每日一题;

import org.apache.commons.collections4.IterableMap;
import org.junit.Test;

import java.util.List;

/**
 * @author :songyaozhang
 * @date :Created 2021/7/13 9:57
 * @description :https://leetcode-cn.com/problems/reverse-linked-list/
 */
public class 反转链表 {
    @Test
    public void test() {
        Solution solution = new Solution();

    }


    //Definition for singly-linked list.
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    class Solution {
        public ListNode reverseList(ListNode head) {
            if (head == null) return null;
            ListNode reverseHead = new ListNode(-1);
            ListNode tmp = head;
            while(tmp != null) {
                ListNode next = tmp.next;
                tmp.next = reverseHead.next;
                reverseHead.next = tmp;
                tmp = next;
            }
            return reverseHead.next;
        }
    }

}
